package cn.zwxky.android.staff.Jurisdiction.Furlough;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.Event.LsfbEvent;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.config.Config;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.DensityUtils;
import com.zgscwjm.lsfbbasetemplate.utils.SN;
import com.zgscwjm.lsfbbasetemplate.utils.T;

import java.util.HashMap;

import cn.zwxky.android.staff.Jurisdiction.Marketplace.TaskApproveDetailsPostEvent;
import cn.zwxky.android.staff.Login.ForgetBean;
import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.LittleUtils;
import cn.zwxky.android.staff.Utils.NoDoubleClickUtils;
import cn.zwxky.android.staff.Utils.URLString;

/**
 * 请假拒绝页面
 * Created by Administrator on 2017/5/4 0004.
 */
@ContentView(R.layout.aty_leave_reject)
public class LeaveRejectActivity extends LsfbActivity {

    @ViewInject(R.id.aty_et_import)
    private EditText et_import;

    private String id;

    private String type;

    @Override
    public void initView() {
        id = getIntent().getStringExtra("id");
        type=getIntent().getStringExtra("type");
        LittleUtils.setsimpletitlebar(this, "拒绝原因");
        TextView textView = new TextView(this);
        textView.setText("提交");
        textView.setTextColor(getResources().getColor(R.color.white_color));
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //收起软键盘
                InputMethodManager imm2 = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm2.hideSoftInputFromWindow(et_import.getWindowToken(), 0);
                if (!NoDoubleClickUtils.isDoubleClick()) {
                    if (type.equals("1")) {
                        //请假
                        post1();
                    }else if (type.equals("2")){
                        //总经理
                        post2();
                    }else if (type.equals("3")){
                        //市场部
                        post3();
                    }
                }

            }
        });
        getTitleBar().setRightView(textView, 0, 0, DensityUtils.dp2px(this, 10), 0);



    }

    @Override
    public void initEvent() {

    }

    @Override
    public void initData() {

    }

    /**
     * 请假审核
     */
    public void post1() {
        if (et_import.getText().toString().isEmpty()) {
            SN.SnackShow(et_import, "请输入拒绝原因");
            return;
        }
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("uid", Config.getUserId());
        hashMap.put("id", id);
        hashMap.put("status", "2");//1通过，2拒绝
        hashMap.put("msg", et_import.getText().toString());//1通过，2拒绝
        new BaseInternet().getData(URLString.LEAVE_OP_UP, hashMap, ForgetBean.class, new ManageLeavePostEvent<ForgetBean>(), false);
    }

    @EventAnnotation
    public void ManageLeavePostEvent(ManageLeavePostEvent<ForgetBean> event) {
        switch (event.getCode()) {
            case 200:
                T.showShort(this, event.getMsg());
                finish();
                ManageLeaveClickEvent2 even = new ManageLeaveClickEvent2();
                even.setData("1");
                LsfbEvent.getInstantiation().post(even);
                break;
            default:
                SN.SnackShow(et_import, event.getMsg());
                break;
        }
    }

    /**
     * 总经理审核
     */
    public void post2() {
        if (et_import.getText().toString().isEmpty()) {
            SN.SnackShow(et_import, "请输入拒绝原因");
            return;
        }
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("uid", Config.getUserId());
        hashMap.put("id", id);
        hashMap.put("status", "2");//1通过，2拒绝
        hashMap.put("msg", et_import.getText().toString());
        new BaseInternet().getData(URLString.EAAPASSMA, hashMap, ForgetBean.class, new TaskApproveDetailsPostEvent<ForgetBean>(), false);
    }

    @EventAnnotation
    public void TaskApproveDetailsPostEvent2(TaskApproveDetailsPostEvent<ForgetBean> event) {
        switch (event.getCode()) {
            case 200:
                T.showShort(this, event.getMsg());
                finish();
                ManageLeaveClickEvent2 even = new ManageLeaveClickEvent2();
                even.setData("1");
                LsfbEvent.getInstantiation().post(even);
                break;
            default:
                SN.SnackShow(et_import, event.getMsg());
                break;
        }
    }

    /**
     * 市场部审核
     */
    public void post3() {
        if (et_import.getText().toString().isEmpty()) {
            SN.SnackShow(et_import, "请输入拒绝原因");
            return;
        }
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("uid", Config.getUserId());
        hashMap.put("id", id);
        hashMap.put("status", "2");//1通过，2拒绝
        hashMap.put("msg", et_import.getText().toString());
        new BaseInternet().getData(URLString.MANAGE_EAAPASSMD, hashMap, ForgetBean.class, new TaskApproveDetailsPostEvent<ForgetBean>(), false);
    }

    @EventAnnotation
    public void TaskApproveDetailsPostEvent(TaskApproveDetailsPostEvent<ForgetBean> event) {
        switch (event.getCode()) {
            case 200:
                T.showShort(this, event.getMsg());
                finish();
                ManageLeaveClickEvent2 even = new ManageLeaveClickEvent2();
                even.setData("1");
                LsfbEvent.getInstantiation().post(even);
                break;
            default:
                SN.SnackShow(et_import, event.getMsg());
                break;
        }
    }





}
